home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 04 / 1 / DISK0416.ZIP / ROFF44.C < prev    next >
C/C++ Source or Header  |  1985-08-08  |  7KB  |  243 lines

  1. /********************************************************/
  2. /*                                                      */
  3. /*                  ROFF4, Version 1.60                 */
  4. /*                                                      */
  5. /*(C) 1983,4 by Ernest E. Bergmann                      */
  6. /*              Physics, Building #16                   */
  7. /*              Lehigh Univerisity                      */
  8. /*              Bethlehem, Pa. 18015                    */
  9. /*                                                      */
  10. /* Permission is hereby granted for all commercial and  */
  11. /* non-commercial reproduction and distribution of this */
  12. /* material provided this notice is included.           */
  13. /*                                                      */
  14. /********************************************************/
  15. /*FEB 18, 1984*/
  16. /*JAN 15, 1984*/
  17. #include "roff4.h"
  18.  
  19. /**************************************************
  20. handles case of leading blanks or tabs; empty lines 
  21. ***************************************************/
  22. leadbl (line)
  23. char *line;
  24. {
  25.       int i, j, white;
  26.       brk();
  27.       /* figure out white space Nov 13*/
  28.       for (white=0, i=0; line[i] == ' ' || line[i] == '\t'; i++ )
  29.       {
  30.             if(line[i]==' ') white++;
  31.             else white=min(RMVAL,TABSIZ*(1+white/TABSIZ));
  32.       }
  33.       if ( line[i] != NEWLINE ) TIVAL += white;
  34.       /* move line to left */
  35.       for(j=0;(line[j]=line[i])!='\0';j++,i++);
  36. }
  37. /*****************************************
  38.                 puts out page header
  39. ******************************************/
  40. phead()
  41. {
  42.       exchange();
  43.       UF=XF=FALSE;
  44.       MCNT=1;
  45.       CURPAG = NEWPAG++;
  46.       if((CURPAG<FIRSTPAGE)||(CURPAG>LASTPAGE)) SUPPRESS=TRUE;
  47.       else SUPPRESS=FALSE;
  48.       OLDLN=-1;
  49.       if(PAGESTOP)
  50.       {
  51.             bdos(2,7);     /*ring bell*/
  52.             bdos(1);        /*wait til char typed at console*/
  53.       }
  54.       PLINENO=0;
  55.       FPLINENO=0;
  56.       if (M1VAL > 0 )
  57.       { 
  58.             VLINENO = M1VAL-1;
  59.             if (CURPAG % 2) puttl3 ( OHEAD, OH2, OH3, CURPAG );
  60.             else puttl3 ( EHEAD, EH2, EH3, CURPAG );
  61.       }
  62.       VLINENO = M1VAL+M2VAL; 
  63.       FVLINENO=0;
  64.       exchange();
  65. }
  66. /**************************************
  67.                 puts out page footer
  68. ***************************************/
  69. pfoot()
  70. {
  71.       exchange();
  72.       UF=XF=FALSE;
  73.       MCNT=1;
  74.       VLINENO = BOTTOM+M3VAL; 
  75.       FVLINENO=0;
  76.       if ( M4VAL > 0 )
  77.       { 
  78.             if(CURPAG % 2)puttl3 ( OFOOT,OF2,OF3, CURPAG );
  79.             else puttl3(EFOOT,EF2,EF3,CURPAG);
  80.       }
  81.       VLINENO = PLVAL;
  82.       FVLINENO=0;
  83.       if (FFEED) putchar(FORMF);
  84.       else padv();
  85.       whole();
  86.       OLDBOT=PLINENO=FPLINENO=0;/*printer at start of newpage*/
  87.       OLDLN=-1;
  88.       exchange();
  89. }
  90. /**********************************************
  91.         space n lines or to bottom of the page
  92. ***********************************************/
  93. space (n)
  94. int n;
  95. {
  96.       brk(); /* flush out last unfilled line */
  97.       if (VLINENO >= BOTTOM)  return; /* end of page */
  98.       if (VLINENO<0) phead(); /* top of page */
  99.       VLINENO += n;
  100.       if (VLINENO >= BOTTOM) pfoot(); /* print footer if bottom */
  101. }
  102. /*******************************************************/
  103. text (line)
  104. char *line;
  105. {
  106.       char wrdbuf [LSZ];
  107.       int i, j, k;
  108.       char *p1, *p2;
  109. #ifdef DEBUGON
  110.       if DEBUG fprintf(STDERR,"\n\nTEXT:<%s>", line);
  111. #endif
  112.       if (line[0] == BLANK || line[0]==NEWLINE || line[0] == TAB)
  113.             leadbl (line);
  114.       if (CEVAL > 0)
  115.       { 
  116.             center(line);
  117.             put(line);
  118.             CEVAL--;
  119.       }
  120.       else if(line[0]==NEWLINE) space(LSVAL);
  121.       else if(!FILL) put(line);
  122.       else while (WE_HAVE_A_WORD == getwrd (line, wrdbuf))
  123.             putwrd (wrdbuf);
  124. }
  125. /******************************************************
  126.         put out a line of text with correct indentation
  127.         underlining if specified
  128. *******************************************************/
  129. put (line)
  130. char *line;
  131. {
  132.       int i,fs,minfs;
  133.       if ((VLINENO < 0)||(VLINENO >= BOTTOM)) phead();
  134.       fs=(VLINENO-OLDLN)*FRVAL;
  135.       minfs=OLDBOT-OUTTOP; 
  136.       if(!(OLDBOT&&OUTTOP)) minfs++;
  137.       while(fs<minfs) {
  138.             fs+=FRVAL; 
  139.             VLINENO++;
  140.       }
  141.       need(0);
  142.       putline(line);
  143.       TIVAL = INVAL;
  144.       VLINENO += LSVAL;
  145.       if (VLINENO >= BOTTOM) pfoot();
  146. }
  147. /***********************************************************
  148. concatenates the word onto the end of OUTBUF for filled text
  149. ************************************************************/
  150. putwrd (wrdbuf) /*Nov 22: SENTENCE*/
  151. char *wrdbuf;
  152. {
  153.       int i, j, k;
  154.       char s[MAXLINE], ch;
  155.       int line_len, new_out_width, wid;
  156.       int nextra;
  157.       skip_blanks (wrdbuf); 
  158.       trunc_bl (wrdbuf);
  159.       wid =1+SENTENCE+strln3(wrdbuf,TRUE,1);/*sets WTOP,WBOT*/
  160.       line_len = RMVAL - TIVAL;
  161.       new_out_width = OUTW+wid;
  162.       if (new_out_width > min (line_len, MAXLINE-1))
  163.       { 
  164.             nextra = min(line_len, MAXLINE-1)-OUTW+1;
  165.             if(OUTBUF[OUTPOS-2]==BLANK) nextra++;
  166.             if(JUSTIFY) spread(OUTBUF,nextra,OUTWRDS);
  167.             brk();
  168.       }
  169.       OUTW += wid;
  170.       OUTcat(wrdbuf);
  171.       OUTSP(); 
  172.       if(SENTENCE) OUTSP();
  173.       OUTWRDS++;
  174.       if(WTOP<OUTTOP) OUTTOP=WTOP;
  175.       if(WBOT>OUTBOT) OUTBOT=WBOT;
  176. }
  177. /**********************************************************
  178.         a new putline routine; sends line to  OUTPUT2
  179. ***********************************************************/
  180. putline (line)
  181. char *line;
  182. {
  183.       char c;
  184.       blanks(TIVAL);
  185.       for(;c=*line;line++) putout(c);
  186.       putout('\0');
  187.       printout();
  188. }
  189. /****************************************/
  190. OUTcat(str)     /*appends string to OUTBUF*/
  191. char *str;
  192. {
  193.       while(OUTBUF[OUTPOS]=*(str++))
  194.             OUTPOS++;
  195. }
  196. /****************************************/
  197. OUTSP()         /*appends BLANK to OUTBUF*/
  198. {
  199.       OUTBUF[OUTPOS++]=BLANK;
  200.       OUTBUF[OUTPOS]='\0';
  201. }
  202. /****************************************/
  203. gloss() /*prints on STDOUT a glossary of .tr chars*/
  204. {
  205.       int i;
  206.       char line[20],tcs;
  207.       put("GLOSSARY:");
  208.       put("USE     <GET>");
  209.       tcs=TCVAL;
  210.       TCVAL |= 128; /*set most significant bit*/
  211.       for(i=1;i<19;i++) line[i]=' ';
  212.       line[0]=tcs;
  213.       line[8]='<';
  214.       line[9]=TCVAL;
  215.       line[11]='>';
  216.       line[12]='\0';
  217.       for(i=' ';i<127;i++)
  218.       {
  219.             if(TPTR[i-' '])
  220.             {
  221.                   line[1]=line[10]=i;
  222.                   put(line);
  223.             }
  224.       }
  225.       TCVAL=tcs;
  226.       SPACE(HUGE);
  227. }
  228. /***************************************/
  229. exchange() /*maintain separate environment for headers and
  230.                 footers*/
  231. {
  232.       int i;
  233.       i=MCNT2; 
  234.       MCNT2=MCNT; 
  235.       MCNT=i;
  236.       i=XF2; 
  237.       XF2=XF; 
  238.       XF=i;
  239.       i=UF2; 
  240.       UF2=UF; 
  241.       UF=i;
  242. }
  243.